<?php
require_once ROOT . 'app/AppController.php';
require_once ROOT . 'app/common/dao/UserDao.php';

class UserTestController extends AppController{

	function viewall() {
		$userDao = new UserDao();
		$userDao->addWhere(UserDao::COL_ID, 100, UserDao::COMP_LESS_THAN);
		$userDao->addWhere(UserDao::COL_EMAIL, 'invalid email', UserDao::COMP_NOT_EQUAL);
		$l = $userDao->select();
		$l['keya'] = 'valuea';
		$this->_form->setList($l);
		$this->_form->set('list1', array('one', 'two'));
		$this->_form->set('value', 'va aaa');
		$this->_form->set('emp', '');
		$this->_form->set('list2', array('one'=>'mot', 'two'=>'hai'));
		$_SESSION['sql'] = $userDao->getSQL();
		$_SESSION['a'] = 1;
		$_SESSION['b'] = 'aaaa';
		$_SESSION['arr'] = array('a'=>'b','c'=>'d');
		//$this->renderView('index/viewall_test.tpl');
		$this->renderView('index/index.tpl');
		//$this->renderView('user/hic.tpl');
	}

	function viewconditions() {
		$userDao = new UserDao();
		$userDao->addWhere(UserDao::COL_ID, 2);
		$userDao->addWhereOr(UserDao::COL_EMAIL, 'user01@email.com');
		$userDao->addWhereOr(UserDao::COL_USERNAME, 'add 1 to 10 update');
		var_dump($userDao->select());
		var_dump($userDao->getSQL());
	}

	function insert() {
		$userDao = new UserDao();
		$userDao->addValue(UserDao::COL_USERNAME, 'name1');
		$userDao->addValue(UserDao::COL_PASSWORD, 'pw 1');
		$userDao->addValue(UserDao::COL_EMAIL, 'e 1');
		$userDao->addValue(UserDao::COL_LEVEL, 1);
		$userDao->addValue(UserDao::COL_GENDER, 1);
		$userDao->insert();
		var_dump($userDao->getLastInsertId());
		var_dump($userDao->getSQL());
	}

	function update() {
		$userDao = new UserDao();
		$userDao->addValue(UserDao::COL_PASSWORD, 'new pw');
		$userDao->addWhere(UserDao::COL_ID, 8);
		$userDao->addWhere(UserDao::COL_EMAIL, 'e 1');

		$userDao->addWhereOr(UserDao::COL_ID, 2);

		$userDao->update();
		var_dump($userDao->getRowEffect());
		var_dump($userDao->getSQL());
	}

	function delete() {
		$userDao = new UserDao();
		$userDao->addWhere(UserDao::COL_ID, 13);
		$userDao->addWhere(UserDao::COL_LEVEL, 1);
		$userDao->addWhere(UserDao::COL_EMAIL, 'email 1');
		$userDao->addWhereOr(UserDao::COL_ID, 10);
		$userDao->addWhereOr(UserDao::COL_EMAIL, " 'email 1' ");
		$userDao->delete();
		var_dump($userDao->getRowEffect());
		var_dump($userDao->getSQL());
	}


}